package com.pay.cloud.activity;

import android.content.Intent;
import android.os.Bundle;

import com.pay.cloud.KeyInfo;
import com.pay.cloud.R;
import com.pay.cloud.ScanListener;
import com.pay.cloud.fragment.WifiApplyFragment;
import com.pay.cloud.fragment.WifiScanFragment;

import static com.pay.cloud.KeyInfo.KEY_CANCEL;
import static com.pay.cloud.KeyInfo.KEY_ENTER;

public class WifiActivity extends AbstractActivity implements ScanListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wifi);
        WifiScanFragment fragment = new WifiScanFragment();
        fragment.setListener(this);
        setMainFragment(fragment);
    }

    @Override
    public boolean onKeyDown(KeyInfo keyInfo) {
        if (keyInfo == KEY_CANCEL || keyInfo == KEY_ENTER) {
            Intent intent = new Intent(this, ConnectActivity.class);
            startActivity(intent);
        }
        return false;
    }

    @Override
    public boolean onScan(String barcode) {
        setMainFragment(new WifiApplyFragment(barcode));
        return true;
    }

}
